package com.tuling.spring;

import com.tuling.UserInterface;
import com.tuling.UserService;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.framework.ProxyFactory;

public class ProxyFactoryDemo {

	public static void main(String[] args) {
		ProxyFactory proxyFactory = new ProxyFactory(new UserService());
		proxyFactory.addAdvice((MethodInterceptor) invocation -> {
			System.out.println("doing A before...");
			Object obj = invocation.proceed();
			System.out.println("doing A after...");
			return obj;
		});
		proxyFactory.addAdvice((MethodInterceptor) invocation -> {
			System.out.println("doing B before...");
			Object obj = invocation.proceed();
			System.out.println("doing B after...");
			return obj;
		});
		UserInterface userInterface = (UserInterface) proxyFactory.getProxy();
		System.out.println(userInterface);
		userInterface.test();
	}
}
